MutableMap

interface MutableMap<K, V> : Map<K, V>

A modifiable collection that holds pairs of objects (keys and values) and supports efficiently retrieving the value corresponding to each key. Map keys are unique; the map holds only one value for each key.

Parameters

K

the type of map keys. The map is invariant in its key type.

V

the type of map values. The mutable map is invariant in its value type.

Types

MutableEntry
Link copied to clipboard
interface MutableEntry<K, V> : Map.Entry<K, V>

Represents a key/value pair held by a MutableMap.

Functions

clear
Link copied to clipboard
abstract fun clear()

Removes all elements from this map.

containsKey
Link copied to clipboard
abstract fun containsKey(key: K): Boolean

Returns true if the map contains the specified key.

containsValue
Link copied to clipboard
abstract fun containsValue(value: V): Boolean

Returns true if the map maps one or more keys to the specified value.

get
Link copied to clipboard
abstract operator fun get(key: K): V?

Returns the value corresponding to the given key, or null if such a key is not present in the map.

getOrDefault
Link copied to clipboard
open fun getOrDefault(key: K, defaultValue: V): V

Returns the value corresponding to the given key, or defaultValue if such a key is not present in the map.

Since Kotlin

1.1
isEmpty
Link copied to clipboard
abstract fun isEmpty(): Boolean

Returns true if the map is empty (contains no elements), false otherwise.

put
Link copied to clipboard
abstract fun put(key: K, value: V): V?

Associates the specified value with the specified key in the map.

putAll
Link copied to clipboard
abstract fun putAll(from: Map<out K, V>)

Updates this map with key/value pairs from the specified map from.

remove
Link copied to clipboard
abstract fun remove(key: K): V?

Removes the specified key and its corresponding value from this map.

open fun remove(key: K, value: V): Boolean

Removes the entry for the specified key only if it is mapped to the specified value.

Since Kotlin

1.1

Properties

entries
Link copied to clipboard
abstract override val entries: MutableSet<MutableMap.MutableEntry<K, V>>

Returns a MutableSet of all key/value pairs in this map.

keys
Link copied to clipboard
abstract override val keys: MutableSet<K>

Returns a MutableSet of all keys in this map.

size
Link copied to clipboard
abstract val size: Int

Returns the number of key/value pairs in the map.

values
Link copied to clipboard
abstract override val values: MutableCollection<V>

Returns a MutableCollection of all values in this map. Note that this collection may contain duplicate values.

Inheritors

AbstractMutableMap
Link copied to clipboard
HashMap
Link copied to clipboard
LinkedHashMap
Link copied to clipboard

Extensions

getOrPut
Link copied to clipboard
inline fun <K, V> MutableMap<K, V>.getOrPut(key: K, defaultValue: () -> V): V

Returns the value for the given key. If the key is not found in the map, calls the defaultValue function, puts its result into the map under the given key and returns it.

getValue
Link copied to clipboard
@JvmName(name = "getVar")
inline operator fun <V, V1 : V> MutableMap<in String, out V>.getValue(thisRef: Any?, property: KProperty<*>): V1

Returns the value of the property for the given object from this mutable map.

iterator
Link copied to clipboard
@JvmName(name = "mutableIterator")
inline operator fun <K, V> MutableMap<K, V>.iterator(): MutableIterator<MutableMap.MutableEntry<K, V>>

Returns a MutableIterator over the mutable entries in the MutableMap.

minusAssign
Link copied to clipboard
inline operator fun <K, V> MutableMap<K, V>.minusAssign(key: K)

Removes the entry with the given key from this mutable map.

inline operator fun <K, V> MutableMap<K, V>.minusAssign(keys: Iterable<K>)

Removes all entries the keys of which are contained in the given keys collection from this mutable map.

inline operator fun <K, V> MutableMap<K, V>.minusAssign(keys: Array<out K>)

Removes all entries the keys of which are contained in the given keys array from this mutable map.

inline operator fun <K, V> MutableMap<K, V>.minusAssign(keys: Sequence<K>)

Removes all entries from the keys of which are contained in the given keys sequence from this mutable map.

plusAssign
Link copied to clipboard
inline operator fun <K, V> MutableMap<in K, in V>.plusAssign(pair: Pair<K, V>)

Appends or replaces the given pair in this mutable map.

inline operator fun <K, V> MutableMap<in K, in V>.plusAssign(pairs: Iterable<Pair<K, V>>)

Appends or replaces all pairs from the given collection of pairs in this mutable map.

inline operator fun <K, V> MutableMap<in K, in V>.plusAssign(pairs: Array<out Pair<K, V>>)

Appends or replaces all pairs from the given array of pairs in this mutable map.

inline operator fun <K, V> MutableMap<in K, in V>.plusAssign(pairs: Sequence<Pair<K, V>>)

Appends or replaces all pairs from the given sequence of pairs in this mutable map.

inline operator fun <K, V> MutableMap<in K, in V>.plusAssign(map: Map<K, V>)

Appends or replaces all entries from the given map in this mutable map.

putAll
Link copied to clipboard
fun <K, V> MutableMap<in K, in V>.putAll(pairs: Array<out Pair<K, V>>)

Puts all the given pairs into this MutableMap with the first component in the pair being the key and the second the value.

fun <K, V> MutableMap<in K, in V>.putAll(pairs: Iterable<Pair<K, V>>)

Puts all the elements of the given collection into this MutableMap with the first component in the pair being the key and the second the value.

fun <K, V> MutableMap<in K, in V>.putAll(pairs: Sequence<Pair<K, V>>)

Puts all the elements of the given sequence into this MutableMap with the first component in the pair being the key and the second the value.

remove
Link copied to clipboard
inline fun <K, V> MutableMap<out K, V>.remove(key: K): V?

Removes the specified key and its corresponding value from this map.

inline fun <K, V> MutableMap<out K, out V>.remove(key: K, value: V): Boolean

Removes the entry for the specified key only if it is currently mapped to the specified value.

set
Link copied to clipboard
inline operator fun <K, V> MutableMap<K, V>.set(key: K, value: V)

Allows to use the index operator for storing values in a mutable map.

setValue
Link copied to clipboard
inline operator fun <V> MutableMap<in String, in V>.setValue(thisRef: Any?, property: KProperty<*>, value: V)

Stores the value of the property for the given object in this mutable map.

withDefault
Link copied to clipboard
@JvmName(name = "withDefaultMutable")
fun <K, V> MutableMap<K, V>.withDefault(defaultValue: (K) -> V): MutableMap<K, V>

Returns a wrapper of this mutable map, having the implicit default value provided with the specified function defaultValue.